<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 00:33:05
 * @LastEditTime: 2023-09-19 13:37:16
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 固定资产
 */

namespace App\Models;

use App\Traits\MaterialTrait;

use App\Traits\AutoCodeTrait;
use App\Traits\VoucherTrait;

class FinanceFixedAsset extends BaseModel
{
    use AutoCodeTrait;
    use MaterialTrait;
    use VoucherTrait;
    public $timestamps = true;
    public $table = "sys_finance_fixed_assets";
    protected $guarded = [];

    protected $casts = [];

    /**
     * 标识
     *
     * @var string
     */
    protected $ACSign = 'FINANCE_FIXED_ASSETS';

    /**
     * 折旧方法
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @author sunkaiyuan
     */
    public function depreciation_method()
    {
        return $this->belongsTo(Dic::class, "depreciation_method_id", "key")->where(function ($q) {
            $q->where("code", 'FinanceDepreciationMethod');
        });
    }

    /**
     * 部门
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @author sunkaiyuan
     */
    public function department()
    {
        return $this->belongsTo(FinanceDepartment::class);
    }
    /**
     * 增加方式
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @author sunkaiyuan
     */
    public function add_method()
    {
        return $this->belongsTo(Dic::class, "add_method_id", "key")->where(function ($q) {
            $q->where("code", 'FinanceFixedAddMethod');
        });
    }
    /**
     * 折旧科目
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @author sunkaiyuan
     */
    public function depreciation_subject()
    {
        return $this->belongsTo(Subject::class);
    }
}
